const { getNewAccess_Token, getImgIdentyByUrl, getImgIdentyByBase64 } = require('../utils/tool.js')
let axios = require('axios')

module.exports = {

    async getWether(ctx, next) {
        let result = ''
        await axios({
            method: 'get',
            url: 'https://api.seniverse.com/v3/weather/daily.json?key=SegOW2yOnYuqW_TsH&location=nanchang&language=zh-Hans&unit=c&start=0&days=5',
            headers: {
                'Content-Type': 'application/json',
                'Accept': 'application/json'
            }
        }).then(res => {
            result = res.data.results
        }).catch(err => {
            console.log(err)
        })
        ctx.body = {
            success: true,
            data: result
        }
    },
    async getBirdByImgUrl(ctx, next) {
        // let { imgUrl } = ctx.request.body;
        let params = ctx.request.body
        let result = null
        await getImgIdentyByUrl(params.imgUrl)
            .then(res => {
                result = res.data
            }).catch(err => {
                console.log(err)
            })
        ctx.body = {
            success: true,
            result
        }
    },
    async searchbirdByBase64(ctx, next) {
        // let { imgUrl } = ctx.request.body;
        let params = ctx.request.body
        let result = null
        // let base64Data = encodeURI(params)
        cl
        await getImgIdentyByBase64(params.image)
            .then(res => {
                result = res
                console.log(res)
            }).catch(err => {
                result = {
                    errdata: err,
                    ok: 0
                }
            })

        ctx.body = {
            success: true,

            result
        }
    },
    async getAccessToken(ctx, next) {
        let res = await getNewAccess_Token()
        ctx.body = {
            success: true,
            access_token: res.access_token
        }
    }
};
